<?php

if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class Sms_model extends CI_Model {
	function __construct() {
		// Call the Model constructor
		parent::__construct ();
		$this->load->database ();
	}
	public function add_sms($requestid, $phone, $shortcode, $content) {
		$contents = explode ( " ", $content );
		// $contents[0] : mã GKD
		// $contents[1] : mã user
		// $contents[2] : mã app
		
		$this->load->model('shortcode_model');
		$codes = $this->shortcode_model->list_shortcode();
		$money = 0;
		foreach($codes as $code){
			if($code->shortcode == $shortcode){
				$money = $code->price;
			}
		} 
		
		$data = array (
				'requestid' => $requestid,
				'phone' => $phone,
				'userid' => $contents [1],
				'app_id' => $contents [2],
				'shortcode' => $shortcode,
				'content' => $content,
				'timeaccess' => date ( "h:s:m" ),
				'dayaccess' => date ( 'd-m-Y' ),
				'money'=>$money,
		);
		$this->db->insert ( 'tbl_mo', $data );
		if ($this->db->affected_rows () != 1) {
			return 0;
		} else {
			return 1;
		}
	}
	
	 
}

?>